<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>报价维护</title>
	<meta name="viewport"
		  content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="/css/oksub.css">
	<script type="text/javascript" src="/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
	<!--数据表格-->
	<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="/lib/layui/layui.js"></script>
<script type="text/javascript" th:inline="javascript">
	layui.use([ "element", "jquery", "table", "form", "laydate", "okLayer",
		"okUtils", "okMock" ], function() {
		var table = layui.table;
		var form = layui.form;
		var laydate = layui.laydate;
		var okLayer = layui.okLayer;
		var okUtils = layui.okUtils;
		var okMock = layui.okMock;
		var $ = layui.jquery;

		laydate.render({
			elem : "#startTime",
			type : "datetime"
		});
		laydate.render({
			elem : "#endTime",
			type : "datetime"
		});
		okLoading.close($);
		var userTable = table.render({
			elem : '#tableId',
			url : "/api/quote/rule/list/"+[[${offerId}]],
			limit : 20,
			page : true,
			toolbar : true,
			toolbar : "#toolbarTpl",
			size : "sm",
			cols : [ [ {
				field : "serialId",
				title : "编号",
				width : 160,
				sort : true
			}, {
				field : "offerName",
				title : "报价类型",
				width : 100
			}, {
				field : "shiftName",
				title : "快件类型",
				width : 100
			},{
				field : "customerName",
				title : "客户",
				width : 100,
				templet:function (d) {
					console.info("customerName="+d.customerName+",customerType="+d.customerType+",customerId="+d.customerId);
					if(d.customerType == 0) {
						return '普通客户'
					} else {
						return d.customerName;
					}
				}
			}, {
				field : "itemName",
				title : "物品类型",
				width : 100
			}, {
				field : "minPrice",
				title : "最低价",
				width : 100
			}, {
				field : "additionalCharge",
				title : "附加费",
				width : 100
			},  {
				field : "servicingTime",
				title : "维护时间",
				width : 100
			},{
				title : "操作",
				width : 200,
				align : "center",
				fixed : "right",
				templet : "#operationTpl"
			} ] ],
			done : function(res, curr, count) {
				console.info(res, curr, count);
			}
		});

		form.on("submit(search)", function(data) {
			userTable.reload({
				where : data.field,
				page : {
					curr : 1
				}
			});
			return false;
		});

		table.on("toolbar(tableFilter)", function(obj) {
			switch (obj.event) {
				case "add":
					add();
					break;
			}
		});

		table.on("tool(tableFilter)", function(obj) {
			var data = obj.data;
			switch (obj.event) {
				case "edit":
					edit(data);
					break;
				case "check":
					edit(data.offerId);
					break;
				case "del":
					del(data.serialId);
					break;
			}
		});

		function add() {
			//var offerTypeId = $("input[name='offerTypeId']").val();
			var offerTypeId = [[${offerId}]];

			console.info("offerTypeId===="+offerTypeId);
			okLayer.open("添加报价信息", "/page/quote/checkAdd/"+offerTypeId, "90%", "90%",
					function() {
						userTable.reload();
					})
		}

		function edit(data) {
			console.info("data.field.serialId2==="+data.serialId);
			okLayer.open("更新信息", "/page/quote/checkEdit/"+data.serialId, "90%", "90%", function(
					layero) {
				console.log(data);
				var iframeWin = window[layero.find("iframe")[0]["name"]];
				iframeWin.initForm(data);
			}, function() {
				userTable.reload();
			})
		}

		function del(serialId) {
			okLayer.confirm("确定要删除吗？", function() {
				okUtils.ajax("/api/quote/checkDelete/"+serialId, "post", true).done(function(response) {
					console.log(response);
					okUtils.tableSuccessMsg(response.msg);
				}).fail(function(error) {
					console.log(error)
				});
			})
		}
	})
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="add">添加报价规则</button>
	</div>
</script>

<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
	<a href="javascript:" title="编辑" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
	<a href="javascript:" title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>


</body>
</html>
